local chengliu = fk.CreateSkill {
    name = "jinhs__chengliu",
}

Fk:loadTranslationTable {
    ["jinhs__chengliu"] = "乘流",
    [":jinhs__chengliu"] = "准备阶段，你可以将一张基本牌当无距离限制的冰【杀】使用，若你未因此造成伤害，你重复此流程。",

    ["#jinhs__chengliu-invoke"] = "你可发动 乘流，将一张基本牌当无距离限制的冰【杀】使用，<br>" ..
        "若你未因此造成伤害，你重复此流程。",

    ["$jinhs__chengliu1"] = "北马临江，曳江北春风，抚江南之锦绣。",
    ["$jinhs__chengliu2"] = "老骥扶剑，奋暮年壮志，益堪舆之万里。",
}

chengliu:addEffect(fk.EventPhaseStart, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(chengliu.name) and player.phase == Player.Start and
            not player:isKongcheng()
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local use = room:askToUseVirtualCard(player, {
            name = "ice__slash",
            skill_name = chengliu.name,
            prompt = "#jinhs__chengliu-invoke",
            extra_data = { bypass_times = true, bypass_distances = true, extraUse = true },
            cancelable = true,
            card_filter = {
                n = 1,
                pattern = ".|.|.|hand|.|basic|."
            },
            skip = true,
        })
        if use then
            event:setCostData(self, { use = use })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local use = event:getCostData(self).use
        local room = player.room
        while true do
            if use == nil then break end
            use.extra_data = use.extra_data or {}
            use.extra_data.jinhs__chengliuUser = player.id
            room:useCard(use)
            use = nil
            local u = room.logic:getEventsByRule(GameEvent.UseCard, 1, function(e)
                return (e.data.extra_data or {}).jinhs__chengliuUser == player.id
            end, nil, Player.HistoryPhase)
            if #u == 0 then return end
            local useEvent = u[1].data
            if not useEvent.damageDealt then
                if player:isAlive() and not player:isKongcheng() then
                    use = room:askToUseVirtualCard(player, {
                        name = "ice__slash",
                        skill_name = chengliu.name,
                        prompt = "#jinhs__chengliu-invoke",
                        extra_data = { bypass_times = true, bypass_distances = true, extraUse = true },
                        cancelable = true,
                        card_filter = {
                            n = 1,
                            pattern = ".|.|.|hand|.|basic|."
                        },
                        skip = true,
                    })
                end
            end
        end
    end
})

return chengliu
